<template>
  <div class="app-container">
    <div class="box">
      <div class="exam">
        <h1>专家</h1>
        <el-form
          :rules="expectRules"
          :model="expect"
          ref="expect"
          label-width="100px"
          class="demo-ruleForm"
        >
          <el-form-item label="总分" prop="sum">
            <el-input v-model.number="expect.sum"></el-input>
          </el-form-item>
          <el-form-item label="及格（分）" prop="pass">
            <el-input v-model.number="expect.pass"></el-input>
          </el-form-item>
          <el-form-item label="考试题数" prop="num">
            <el-input v-model.number="expect.num"></el-input>
          </el-form-item>
          <el-form-item label="答题时长" prop="time">
            <el-input v-model.number="expect.time"></el-input>
          </el-form-item>
        </el-form>
      </div>
      <hr />
      <div class="exam">
        <h1>商务经理考试</h1>
        <el-form
          :rules="businessRules"
          :model="business"
          ref="business"
          label-width="100px"
          class="demo-ruleForm"
        >
          <el-form-item label="总分" prop="sum">
            <el-input v-model.number="business.sum"></el-input>
          </el-form-item>
          <el-form-item label="及格（分）" prop="pass">
            <el-input v-model.number="business.pass"></el-input>
          </el-form-item>
          <el-form-item label="考试题数" prop="num">
            <el-input v-model.number="business.num"></el-input>
          </el-form-item>

          <el-form-item label="答题时长" prop="time">
            <el-input v-model.number="business.time"></el-input>
          </el-form-item>
        </el-form>
      </div>
    </div>
    <el-button
      type="primary"
      @click="saveFn"
      v-hasPermi="['assess:examOption:edit']"
      >保存</el-button
    >
  </div>
</template>
<script>
import {
  getExamOptionListApi,
  getExamOptionEdittApi,
} from "@/wss/api/HumanResources/EM/Setting.js";
export default {
  data() {
    return {
      expect: {
        id: "1",
        pass: "",
        sum: "",
        num: "",
        time: "",
      },
      business: {
        id: "2",
        pass: "",
        sum: "",
        num: "",
        time: "",
      },
      businessRules: {
        sum: [
          {
            type: "number",
            required: true,
            message: "请输入总分",
            trigger: "blur",
          },
        ],
        pass: [
          {
            type: "number",
            required: true,
            message: "请输及格分数",
            trigger: "change",
          },
        ],
        num: [
          {
            type: "number",
            required: true,
            message: "请输入考试题数",
            trigger: "blur",
          },
        ],
        time: [
          {
            message: "请输入考试时长",
            type: "number",
            required: true,
            trigger: "blur",
          },
        ],
      },
      expectRules: {
        sum: [
          {
            type: "number",
            required: true,
            message: "请输入总分",
            trigger: "blur",
          },
        ],
        pass: [
          {
            type: "number",
            required: true,
            message: "请输及格分数",
            trigger: "blur",
          },
        ],
        num: [
          {
            type: "number",
            required: true,
            message: "请输入考试题数",
            trigger: "blur",
          },
        ],
        time: [
          {
            message: "请输入总分",
            type: "number",
            required: true,
            trigger: "blur",
          },
        ],
      },
    };
  },
  methods: {
    // 保存
    async saveFn() {
      try {
        await this.$refs.business.validate();
        this.$refs.expect.validate();
        const business = await getExamOptionEdittApi(this.expect);
        const expect = await getExamOptionEdittApi(this.business);

        if ((business.code == 200, expect.code == 200)) {
          this.getExamOptionListFn;
          this.$message({
            type: "success",
            message: business.msg,
          });
        }
      } catch (error) {
        this.$message({
          type: "warning",
          message: "无效",
        });
        console.log(error);
      }
    },
    // 获取分数
    async getExamOptionListFn() {
      let { rows, code } = await getExamOptionListApi();
      // console.log(result);
      if (code === 200) {
        rows.forEach((element) => {
          console.log(element);
          if (element.type == 2) {
            this.business = element;
          } else {
            this.expect = element;
          }
        });
      }
    },
  },
  mounted() {
    this.getExamOptionListFn();
  },
};
</script>
<style lang="scss" scoped>
.app-container {
  background-color: #f5f5f5;
  .exam {
    padding: 10px;
    width: 800px;
  }
  .box {
    background-color: #ffffff;
    padding-bottom: 10px;
    padding-left: 10px;
  }
  ::v-deep .el-button--primary {
    margin-top: 10px;
    height: 40px;
    width: 160px;
  }
}
</style>